package com.gorkr.cronback.pattern.designPattern.decorator;

import com.gorkr.cronback.pattern.CronPattern;
import com.gorkr.cronback.pattern.designPattern.factory.ValueMatcherFactory;
import com.gorkr.cronback.pattern.designPattern.proxy.CronPatternInterface;

import java.util.Calendar;

/**
 * @author gorkr
 * @title: SecondCronPatternDecorator
 * @projectName cron
 * @description: 装饰器增加秒解析功能
 * @date 2021/12/2711:38
 */
public class SecondCronPatternDecorator implements CronPatternInterface {
    private String cronString;

    private CronPatternInterface cronPattern;

    public SecondCronPatternDecorator(String pattern, ValueMatcherFactory valueMatcherFactory) throws Exception {
        this.cronString = pattern;
        String cronWithoutSecnond;
        // todo: 拆出second 并将剩余部分赋值给 cronWithoutSecond
        cronWithoutSecnond = "* * * * *";


        this.cronPattern = new CronPattern(cronWithoutSecnond,valueMatcherFactory);
    }

    @Override
    public boolean match(Calendar calendar) throws Exception {
        final boolean resWithoutSecond = cronPattern.match(calendar);

        // todo: 增加对秒的判定
        boolean resSecond = true;

        return resWithoutSecond&&resSecond;
    }
}
